package com.zmn.plat.admin.controller.difficult.ratio;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.model.entity.base.difficult.ratio.DifficultRatio;
import com.zmn.plat.model.entity.base.difficult.ratio.DifficultRatioQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2021/1/8 18:27
 **/
@Controller
@RequestMapping("/difficult/ratio/")
@Slf4j
public class DifficultRatioListController extends DifficultRatioBaseController{

    /**
     * region 区域列表
     *
     * @param query
     * @return
     * @modifier tanbiao 2019/09/06 查询新增条件
     */
    @RequestMapping(value = "list")
    @RequiresPermissions("/difficult/ratio/list.action")
    public ModelAndView list(@ModelAttribute DifficultRatioQuery query) {
        List<DifficultRatio> items = difficultRatioService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("difficult/ratio/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);

        return mav;
    }

    /**
     * region 区域详情
     *
     * @param difficultId
     * @return
     */
    @RequestMapping("detail")
    @RequiresPermissions("/difficult/ratio/detail.action")
    public ModelAndView detail(@RequestParam(value = "difficultId", defaultValue = "0") Integer difficultId) {

        DifficultRatio difficultRatio;
        if (NumberUtil.isNullOrZero(difficultId)) {
            difficultRatio = new DifficultRatio();
        } else {
            difficultRatio = difficultRatioService.findByKey(difficultId);
        }

        ModelAndView mav = new ModelAndView("difficult/ratio/detail");
        mav.addObject("difficultRatio", difficultRatio);
        mav.addObject("yesOrNoList", GlobalDict.getYesOrNoList());

        return mav;
    }
}
